//
//  ViewController.m
//  PeiJue
//
//  Created by lxy on 2017/9/21.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()

@property (nonatomic ,strong) UIButton *navBackBt;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 设置导航栏的背景图片
    //[self.navigationController.navigationBar setBackgroundImage:[UIImage imageFromContextWithColor:[UIColor yellowColor]] forBarMetrics:UIBarMetricsDefault];
    
    // 设置返回按钮
    if (self.navigationController.viewControllers.count>1) {
        [self addNavDefaultBackBt];
    }
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self setNeedsStatusBarAppearanceUpdate];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/* 状态栏设置 */
- (BOOL)prefersStatusBarHidden {
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationFade;
}

#pragma mark -  Events
- (void)navBackBtAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Privates


#pragma mark - Publics
- (void) addNavDefaultBackBt {
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.navBackBt];
}


#pragma mark - Getters
- (UIButton *)navBackBt {
    if (!_navBackBt) {
        _navBackBt = [UIButton buttonWithType:UIButtonTypeCustom];
        _navBackBt.frame = CGRectMake(0, 0, 44, 44);
        [_navBackBt setImage:[UIImage imageNamed:@"nav_return"] forState:UIControlStateNormal];
        //_navBackBt.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        [_navBackBt addTarget:self action:@selector(navBackBtAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _navBackBt;
}

@end
